package com.mengtian_tech.tju.dataquery.api.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.mengtian_tech.tju.dataquery.api.service.AskLeaveService;
import com.mengtian_tech.tju.dataquery.api.service.AsyncDateService;

@Component
public class AsyncLeaveInfo {

	@Autowired
	AskLeaveService askLeaveService;
	
	@Autowired
	AsyncDateService asyncDateService;
 
	/**
	 * 同步数据
	 */
	@Scheduled(cron = "0 */10 * * * ? ")
	public void run() {
		
		int total = 0;
		try {
			int count = askLeaveService.asyncLeave();
			while(count > 0) {
				total += count;
				count = askLeaveService.asyncLeave();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
		}
		
		try {
			int count = this.askLeaveService.dealData();
			while(count > 0) {
				count = this.askLeaveService.dealData();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		asyncDateService.updateDate("02", total);
		
	}
	

	/**
	 * 同步状态
	 */
	@Scheduled(cron = "0 */20 * * * ? ")
	public void asyncState() {
		try {
			askLeaveService.asyncState();
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
		}
	}	
	
	
}
